import {List} from '../../../../mock/product/'

module.exports = {
	name: 'list',
	data() {
		return {
			productList:[],
			editForm:[],
			editDialogShow:false,
			page:2,
			size:3,
			total:4,
			currentPage:1,
			rules:{
				waterFactoryName:[{
					required:true,message:'水厂不能为空'
				}],
				brand:[{
					required:true,message:'品牌名不能为空'
				}],
				name:[{
					required:true,message:'商品名不能为空'
				}],
				standard:[{
					required:true,message:'规格不能为空'
				}],
				disposable:[{
					required:true,message:'是否一次性用水不能为空'
				}],
				blBuPr:[{
					required:true,message:'空桶价格不能为空'
				}],
				prForWaUs:[{
					required:true,message:'售价不能为空'
				}],
				prForWaDe:[{
					required:true,message:'配送提成不能为空'
				}],
				producerPrice:[{
					required:true,message:'出厂价不能为空'
				}]
			},
		}
	},
	methods: {
		getList(){
			this.productList = this.formProduct(List.data); 
		},
		formProduct(productList) {
			return productList.map(product => {
				product.createTime = this.$$formatTime1(product.createTime);
				product.disposable = this.$$formDisposable(product.disposable);
				return product;
			})
		},
		handleCurrentChange(val) {
		    this.page = val;
		    this.getList();
		},
		editProduct(item) {
			this.editDialogShow = true;
			Object.assign(this.editForm,item);
		},
		//删除单个商品
		deleteProduct(productID,productName) {
			const h = this.$createElement;
			        this.$msgbox({
			          title: '确认删除',
			          message: h('p', null, [
			            h('span', null, '确认删除商品 '),
			            h('span', { style: 'color: teal' }, productName),
			            h('span',null,'？')
			          ]),
			          showCancelButton: true,
			          confirmButtonText: '确定',
			          cancelButtonText: '取消',
			          beforeClose: (action, instance, done) => {
			            if (action === 'confirm') {
			              instance.confirmButtonLoading = true;
			              instance.confirmButtonText = '删除中...';
			              if(productID){
			              	console.log(productID);
			              	done();
			              	instance.confirmButtonLoading = false;
			              }
			            } else {
			              done();
			            }
			          }
			        }).then(action => {
			          this.$message({
			            type: 'info',
			            message: '删除成功 ' 
			          });
			        });
		},
	},
	created() {
		this.getList();
	}
}